package com.msg.handler;

import java.lang.reflect.Method;

import org.apache.mina.core.session.IoSession;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.alibaba.fastjson.JSONObject;
import com.msg.utils.MsgSrvUtils;

/**
 * 协议分发类(client->MsgSrv)
 * 
 * @author 王畅
 * @version 创建时间：2015-6-16 下午02:50:09
 */
public class CliMsgDispatcher {
	private static Logger log = LoggerFactory.getLogger(CliMsgDispatcher.class);

	/**
	 * 协议转发(Client->MsgSrv)
	 * 
	 * @author 王畅
	 * @param session
	 * @param userId
	 * @param msgId
	 * @param data
	 * @throws Exception
	 */
	public static void receiveMsg(IoSession session, String userId, int msgId, JSONObject data) throws Exception {

		Method method = MsgSrvUtils.getInstance().getCliMsgHanderMethod(msgId);
		if (method == null)
			log.error("未知协议：" + data.toString());
		else
			method.invoke(method.getClass(), new Object[] { session, userId, data });
	}
}
